package cc.linker.steplink.crm.merchanth5.controller;

import cc.linker.steplink.crm.commons.domain.WxUser;
import cc.linker.steplink.crm.commons.enums.IntegralEnums;
import cc.linker.steplink.crm.merchanth5.service.CustomerIntegralService;
import cc.linker.steplink.crm.response.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: 用户积分调整
 * @Author: ch
 * @Date: Created in 2021/4/6 14:57
 * @Version: 1.12.25
 */
@Slf4j
@RestController
@RequestMapping("/h5/customerIntegral")
public class CustomerIntegralController {

    @Autowired
    private CustomerIntegralService customerIntegralService;

    /**
     * @param customerId        用户ID
     * @param behavior          用户行为比如：购买了XXXXXXXXXX商品
     * @param integralFieldName 积分属性名称
     * @param score             增减的积分
     * @param sourceFieldName   来源属性名称
     * @param orgId             机构ID
     * @Description：添加用户积分（包含雅智捷）
     * @DateTime：2020/9/11 10:04
     * @Params：
     * @Return：
     */
    @PostMapping("/addIntegralCustomerLog")
    public void addIntegralCustomerLog(@RequestBody Map<String, Object> params
    ) {
//        String customerId,String msg,String score, String orgId,nteger type,String source
        if(StringUtils.isEmpty(params.get("customerId")) || StringUtils.isEmpty(params.get("msg"))|| StringUtils.isEmpty(params.get("score"))
                || StringUtils.isEmpty(params.get("orgId"))|| StringUtils.isEmpty(params.get("type"))|| StringUtils.isEmpty(params.get("source"))){
            throw GlobalException.build("参数错误！");
        }
        String customerId = params.get("customerId").toString();
        String msg = params.get("msg").toString();
        String score = params.get("score").toString();
        String orgId = params.get("orgId").toString();
        Integer type = Integer.valueOf(params.get("type").toString());
        String source = params.get("source").toString();
        String sourceType = IntegralEnums.customerScore.toString();
        if(type==2){
            sourceType = IntegralEnums.customerGrowthScore.toString();
        }
        String sourceFieldName = IntegralEnums.other.toString();
        if("route".equals(source)){
            sourceFieldName = IntegralEnums.clockWxMini.toString();
        }
        customerIntegralService.addIntegralCustomerLog(customerId,msg, sourceType,score,sourceFieldName,orgId);
    }
}


